<?php
class Controller_Admin_Hotsearch extends Controller_Template
{
	public function __construct($request,$response)
	{
		header("Content-Type:text/html;charset=utf-8"); 

		parent::__construct($request,$response);
		
		$this->template	= ('smarty:admin/home/hotsearch');
	}

	public function action_index($type = 1)
	{
		$type	= intval($type);

		if($type == 1)
			$key_word	= '商品热词搜索';
		elseif($type == 2)
			$key_word	= '商铺热词搜索';
		
		$words	= Hotword::get_all_searchwords($type);
		$this->template->set_filename('smarty:admin/home/hotsearch');
		$this->template->set('str', $words);
		$this->template->set('type', $type);
		$this->template->set('key_word', $key_word);
		$this->template->set('function_name', 'hotsearch');
		$this->template->set('page_title', $key_word);
		$this->response->body($this->template->render());	
	}

	public function action_add_hot()
	{

		$act	= $this->request->post('action');
		$words	= $this->request->post('words');
		$type	= intval($this->request->post('word_type'));

		if(empty($words)|| $type <= 0)
			return false;

		if($act == 'add')
		{
			$rs = explode(',', $words);	
			
			Hotword::insert_searchword($rs, $type);	
		}
	
		$url= '/hotsearch/index/'.$type;

		$this->request->redirect($url , $code=302);
	}
}
?>
